class OrderItem {
  final String id;
  final String? orderNo;
  final String? userName;
  final String? userPhone;
  final String itemType;
  final String? itemTypeDesc;
  final String itemName;
  final double amount;
  final String? payType;
  final String? payTypeDesc;
  final int payStatus;
  final String? payStatusDesc;
  final String? payTime;
  final String createTime;

  OrderItem({
    required this.id,
    this.orderNo,
    this.userName,
    this.userPhone,
    required this.itemType,
    this.itemTypeDesc,
    required this.itemName,
    required this.amount,
    this.payType,
    this.payTypeDesc,
    required this.payStatus,
    this.payStatusDesc,
    this.payTime,
    required this.createTime,
  });

  factory OrderItem.fromJson(Map<String, dynamic> json) {
    return OrderItem(
      id: json['id'].toString(),
      orderNo: json['orderNo'],
      userName: json['userName'],
      userPhone: json['userPhone'],
      itemType: json['itemType'] ?? '',
      itemTypeDesc: json['itemTypeDesc'],
      itemName: json['itemName'] ?? '',
      amount: (json['amount'] ?? 0.0).toDouble(),
      payType: json['payType'],
      payTypeDesc: json['payTypeDesc'],
      payStatus: json['payStatus'] ?? 0,
      payStatusDesc: json['payStatusDesc'],
      payTime: json['payTime'],
      createTime: json['createTime'] ?? '',
    );
  }
}

class Order {
  final String id;
  final String orderNo;
  final String userId;
  final String userName;
  final String userPhone;
  final String deptId;
  final String deptName;
  final String pondId;
  final String pondName;
  final String seatId;
  final String seatCode;
  final int orderType;
  final String orderTypeDesc;
  final String startTime;
  final String appointmentSegmentId;
  final int status;
  final String statusDesc;
  final double totalAmount;
  final String createTime;
  final String updateTime;
  final List<OrderItem> orderItems;

  Order({
    required this.id,
    required this.orderNo,
    required this.userId,
    required this.userName,
    required this.userPhone,
    required this.deptId,
    required this.deptName,
    required this.pondId,
    required this.pondName,
    required this.seatId,
    required this.seatCode,
    required this.orderType,
    required this.orderTypeDesc,
    required this.startTime,
    required this.appointmentSegmentId,
    required this.status,
    required this.statusDesc,
    required this.totalAmount,
    required this.createTime,
    required this.updateTime,
    required this.orderItems,
  });

  factory Order.fromJson(Map<String, dynamic> json) {
    return Order(
      id: json['id'].toString(),
      orderNo: json['orderNo'] ?? '',
      userId: json['userId'].toString(),
      userName: json['userName'] ?? '',
      userPhone: json['userPhone'] ?? '',
      deptId: json['deptId'].toString(),
      deptName: json['deptName'] ?? '',
      pondId: json['pondId'].toString(),
      pondName: json['pondName'] ?? '',
      seatId: json['seatId'].toString(),
      seatCode: json['seatCode'] ?? '',
      orderType: json['orderType'] ?? 0,
      orderTypeDesc: json['orderTypeDesc'] ?? '',
      startTime: json['startTime'] ?? '',
      appointmentSegmentId: json['appointmentSegmentId'].toString(),
      status: json['status'] ?? 0,
      statusDesc: json['statusDesc'] ?? '',
      totalAmount: (json['totalAmount'] ?? 0.0).toDouble(),
      createTime: json['createTime'] ?? '',
      updateTime: json['updateTime'] ?? '',
      orderItems: (json['orderItems'] as List<dynamic>?)
          ?.map((item) => OrderItem.fromJson(item))
          .toList() ?? [],
    );
  }
}

class OrderListResponse {
  final int total;
  final List<Order> rows;
  final int code;
  final String msg;

  OrderListResponse({
    required this.total,
    required this.rows,
    required this.code,
    required this.msg,
  });

  factory OrderListResponse.fromJson(Map<String, dynamic> json) {
    return OrderListResponse(
      total: json['total'] ?? 0,
      rows: (json['rows'] as List<dynamic>?)
          ?.map((order) => Order.fromJson(order))
          .toList() ?? [],
      code: json['code'] ?? 0,
      msg: json['msg'] ?? '',
    );
  }
}